package com.one.group.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.web.client.RestTemplate;

/**
 * {@code @Create:}  2025-10-15  16 : 31
 * {@code @Author:} Cherry
 * {@code @ToAuthor:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);

        // key 序列化方式 采用 StringRedisSerializer
        redisTemplate.setKeySerializer(RedisSerializer.string());
        // value 序列化 采用 json 序列化
        redisTemplate.setValueSerializer(RedisSerializer.json());

        // hash key 序列化方式 采用 StringRedisSerializer
        redisTemplate.setHashKeySerializer(RedisSerializer.string());
        // hash value 序列化方式 采用 json 序列化
        redisTemplate.setHashValueSerializer(RedisSerializer.json());

        // 设置数据库序列化方式
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
